package com.xgkj.diyiketang.task;

import android.util.Log;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.xgkj.diyiketang.ProtocolConst;
import com.xgkj.diyiketang.data.VideoInfo;
import com.xgkj.diyiketang.data.VideoParentInfo;
import com.xgkj.diyiketang.http.CouponHttpRequest;
import com.xgkj.diyiketang.http.CouponHttpResponse;
import com.xgkj.diyiketang.http.engine.CouponHttpBaseTask;
import com.xgkj.diyiketang.http.engine.TaskResultCode;
import com.xgkj.diyiketang.util.LogUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrater on 2015/12/7.
 */
public class  VideoListTask extends CouponHttpBaseTask {
    private String schoolName;
    private String mApple;
    public VideoListTask(String school,String apple) {
        super(TaskType.VIDEO_LIST_TASK);
        schoolName = school;
        mApple = apple;
    }

    @Override
    protected void prepareRequest() {
        super.prepareRequest();
        if (mPhase == TASK_PHASE_INIT) {
            CouponHttpRequest request = new CouponHttpRequest(
                    RequestType.VIDEO_LIST_REQUEST);
            request.setApiNo(ApiNo.VIDEO_LIST);
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("schoolName",schoolName);
            jsonObject.put("apple",mApple);
            request.setData(jsonObject.toString());
            addRequest(request);
        }
    }

    @Override
    protected void processResponseData(CouponHttpResponse response) {
        JSONObject json = response.getBody();

        List<VideoParentInfo> list = new ArrayList<VideoParentInfo>();
        if (json != null) {
            //JSONObject jsonString = json.getJSONObject("data");
                list = JSON.parseArray(
                        json.getString("data"),
                        VideoParentInfo.class);

        }
        notifyTaskCompleted(TaskResultCode.SUCCESS, list);
    }
}
